#include "stdafx.h"
#include "DispositifD3D.h"
#include "util.h"
#include "Shader.h"
using namespace UtilitairesDX;

namespace PM3D
{
    Shader::Shader(const std::wstring& filename, Dispositif* device)
        : filename_(filename), effect_(nullptr)
    {
        DispositifD3D* d3dDeviceD3D = dynamic_cast<DispositifD3D*>(device);
        IDirect3DDevice9* d3dDevice = d3dDeviceD3D->getD3DDevice();

        ID3DXBuffer* errorShaders = nullptr;

#ifdef _DEBUG
        D3DXCreateEffectFromFile(d3dDevice,
            filename_.c_str(), 0, 0,
            D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION,
            0, &effect_, &errorShaders);

#else
        D3DXCreateEffectFromFile(d3dDevice,
            filename_.c_str(), 0, 0, 0, 0, &effect_, &errorShaders);
#endif

        if (errorShaders)
        {
            MessageBoxA(0, (char*)errorShaders->GetBufferPointer(),
                "ERREUR Compilation Shader\n", 0);
        }

        DXRelacher(errorShaders);
    }

    Shader::~Shader()
    {
        DXRelacher(effect_);
    }
}   // namespace PM3D
